using MicroMsg.Storage;
using System;
using System.Windows.Threading;
namespace MicroMsg.UI.UserContrl
{
	public class VoicePlayerContext
	{
		private const string TAG = "VoicePlayerContext";
		private DispatcherTimer progressTimer;
		private ProgressCallBack mProgressCallBack;
		public ChatMsg chatMsg_0;
		public ChatVoiceItem chatVoiceItem;
		public MassSendVoiceItem massVoiceItem;
		public string voiceUrl;
		private bool mIsPlaying;
		public bool isPlaying
		{
			get
			{
				return this.mIsPlaying;
			}
			set
			{
				if (value == this.mIsPlaying)
				{
					return;
				}
				this.mIsPlaying = value;
				this.SetMenuItemWhenPlaying(this.mIsPlaying);
				if (this.mIsPlaying)
				{
					this.progressTimer.Start();
					this.SetProgress(0.0);
					return;
				}
				this.progressTimer.Stop();
				this.SetProgress(100.0);
			}
		}
		public VoicePlayerContext(ProgressCallBack _ProgressCallBack)
		{
			this.progressTimer = new DispatcherTimer();
			this.progressTimer.add_Tick(new EventHandler(this.progressTimer_Tick));
			TimeSpan interval = new TimeSpan(0, 0, 0, 0, 300);
			this.progressTimer.set_Interval(interval);
			this.mProgressCallBack = _ProgressCallBack;
		}
		private void progressTimer_Tick(object sender, EventArgs e)
		{
			if (this.mProgressCallBack == null)
			{
				return;
			}
			this.mProgressCallBack(this);
		}
		public void SetMenuItemWhenPlaying(bool isPlaying)
		{
			if (this.chatVoiceItem == null && this.massVoiceItem == null)
			{
				return;
			}
			if (this.chatVoiceItem != null)
			{
				this.chatVoiceItem.SetPlayingStatus(isPlaying);
				return;
			}
			if (this.massVoiceItem != null)
			{
				this.massVoiceItem.SetPlayingStatus(isPlaying);
			}
		}
		public void SetProgress(double progress)
		{
			if (this.chatVoiceItem == null && this.massVoiceItem == null)
			{
				return;
			}
			if (progress >= 100.0)
			{
				if (this.chatVoiceItem != null)
				{
					this.chatVoiceItem.EndProgressChange();
					return;
				}
				if (this.massVoiceItem != null)
				{
					this.massVoiceItem.EndProgressChange();
					return;
				}
			}
			else
			{
				if (this.chatVoiceItem != null)
				{
					this.chatVoiceItem.ProgressFlagChange();
					return;
				}
				if (this.massVoiceItem != null)
				{
					this.massVoiceItem.ProgressFlagChange();
				}
			}
		}
	}
}
